package com.hddz.acquisition.view;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hddz.acquisition.R;
import com.hddz.acquisition.model.ResponseItem;

public class Free1Adapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private List<ResponseItem> mListItem;
	private Context mContext;
	private Boolean nodata = false;

	public Free1Adapter(Context context) {
		super();
		this.mContext = context;
		this.mInflater = LayoutInflater.from(context);
		this.mListItem = new ArrayList<ResponseItem>();
	}

	public void updateList(List<ResponseItem> list) {
		this.mListItem.clear();
		this.mListItem.addAll(list);
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mListItem.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mListItem.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.view_stock_grounding_color_list_item, null);
			holder = new Holder();
			holder.txt_invname = (TextView) convertView.findViewById(R.id.txt_invname);
			holder.txt_free1 = (TextView) convertView.findViewById(R.id.txt_free1);
			holder.txt_horse = (TextView) convertView.findViewById(R.id.txt_horse);
			holder.txt_quantity = (TextView) convertView.findViewById(R.id.txt_quantity);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}

		ResponseItem item = mListItem.get(position);
		holder.txt_invname.setText(item.cInvName);
		holder.txt_free1.setText(item.cFree1);
		holder.txt_horse.setText(item.iHorse + "");
		holder.txt_quantity.setText(item.iQuantity + "");

		return convertView;
	}

	class Holder {
		private TextView txt_invname, txt_free1, txt_horse, txt_quantity;
	}
}
